import BaseController from "../../cfw/mvc/BaseController";
import LobbyController from "../lobby/LobbyController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex, ItemState } from "../../cfw/tools/Define";
import DininghallManager from "./model/DininghallManager";
import FoodItemModel from "./model/FoodItemModel";
import SDKManager from "../../sdk/SDKManager";
import { ResultState } from "../../sdk/SDKConfig";

export default class DininghallController extends BaseController {


    private static ins: DininghallController;



    static instance() {
        if (!this.ins) {
            this.ins = new DininghallController()
        }
        return this.ins;
    }
    intoLayer() {
        ModuleManager.setModuleID(ModuleID.PUBLIC)
        this.pushView('prefabs/DininghallView', 'DininghallView', DininghallManager.instance(), ModuleManager.getLoader(), UIIndex.ROOT)
    }

    back() {
        this.gotoLobby()
    }

    gotoLobby() {
        LobbyController.instance().intoLayer()
    }

    gotoNext() {
        this.gotoLobby()
    }

    openItem(model: FoodItemModel) {
        SDKManager.getChannel().showRewardAd(0, (state: ResultState) => {
            cc.log('DininghallController showRewardAd  state == ', state)
            if (state == ResultState.YES) {
                model.setState(ItemState.GOT)
            }
        })
    }
}
